import javax.swing.*;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.*;

public class SimpleGUI implements ActionListener {
	
	private JButton b; // we need remember reference to button for changing it's text later
	
	public static void main(String args[]) {
		SimpleGUI g = new SimpleGUI(); 	// we can't call "this" in static method main, so we are forced to create GUI instance
		g.go();
	}
	
	public void go() {
		JFrame f = new JFrame(); 		// creating frame (window skeleton)
		
		b = new JButton("Click me!");	// creating button
		b.addActionListener(this); 		// adding current object as listener for button events
		
//		DrawPanel d = new DrawPanel();	// creating draw panel (custom draw widget)
		
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // setting up close operation for frame
		f.getContentPane().add(b);		// adding control to frame
		
		f.setSize(480, 320);			// resizing frame
		Dimension sb = Toolkit.getDefaultToolkit().getScreenSize(); // obtaining screen size from awt.Toolkit
		f.setLocation((sb.width - f.getWidth())/2, (sb.height - f.getHeight())/2); // calculating center of screen
		
		f.setVisible(true);				// displaying frame with controls (necessary to make window visible
	}

	@Override
	public void actionPerformed(ActionEvent e) { // it's the override method, handling on-click event
		b.setText("I've been clicked");
	}
}
